package com.dkd.music.controller;

import com.dkd.common.annotation.Log;
import com.dkd.common.core.controller.BaseController;
import com.dkd.common.core.domain.AjaxResult;
import com.dkd.common.core.page.TableDataInfo;
import com.dkd.common.enums.BusinessType;
import com.dkd.common.utils.poi.ExcelUtil;
import com.dkd.music.domain.Album;
import com.dkd.music.service.IAlbumService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 专辑Controller
 * 
 * @author grz
 * @date 2025-10-25
 */
@RestController
@RequestMapping("/music/album")
public class AlbumController extends BaseController
{
    @Autowired
    private IAlbumService albumService;

    /**
     * 提供给其他模块进行远程搜索的专辑列表
     * @param album 查询条件，可以包含 name
     * @return 经过分页的、轻量级的专辑列表
     */
    @GetMapping("/selectList")
    public TableDataInfo selectList(Album album)
    {
        // 开启分页，这样无论查出多少数据，都只返回第一页
        startPage();
        // 使用若依生成的 selectAlbumList 方法，它天生就支持根据 name 进行模糊查询
        List<Album> list = albumService.selectAlbumList(album);
        return getDataTable(list);
    }

    /**
     * 查询专辑列表
     */
    @PreAuthorize("@ss.hasPermi('music:album:list')")
    @GetMapping("/list")
    public TableDataInfo list(Album album)
    {
        startPage();
        List<Album> list = albumService.selectAlbumList(album);
        return getDataTable(list);
    }

    /**
     * 导出专辑列表
     */
    @PreAuthorize("@ss.hasPermi('music:album:export')")
    @Log(title = "专辑", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Album album)
    {
        List<Album> list = albumService.selectAlbumList(album);
        ExcelUtil<Album> util = new ExcelUtil<Album>(Album.class);
        util.exportExcel(response, list, "专辑数据");
    }

    /**
     * 获取专辑详细信息
     */
    @PreAuthorize("@ss.hasPermi('music:album:query')")
    @GetMapping(value = "/{albumId}")
    public AjaxResult getInfo(@PathVariable("albumId") Long albumId)
    {
        return success(albumService.selectAlbumByAlbumId(albumId));
    }

    /**
     * 新增专辑
     */
    @PreAuthorize("@ss.hasPermi('music:album:add')")
    @Log(title = "专辑", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Album album)
    {
        return toAjax(albumService.insertAlbum(album));
    }

    /**
     * 修改专辑
     */
    @PreAuthorize("@ss.hasPermi('music:album:edit')")
    @Log(title = "专辑", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Album album)
    {
        return toAjax(albumService.updateAlbum(album));
    }

    /**
     * 删除专辑
     */
    @PreAuthorize("@ss.hasPermi('music:album:remove')")
    @Log(title = "专辑", businessType = BusinessType.DELETE)
	@DeleteMapping("/{albumIds}")
    public AjaxResult remove(@PathVariable Long[] albumIds)
    {
        return toAjax(albumService.deleteAlbumByAlbumIds(albumIds));
    }
}
